//
// Created by xili on 2024/8/22 11:10.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int finalPositionOfSnake(int n, vector <string> &commands) {
        int i = 0, j = 0;
        for (auto &s: commands) {
            switch (s[0]) {
                case 'U':
                    i--;
                    break;
                case 'D':
                    i++;
                    break;
                case 'L':
                    j--;
                    break;
                default:
                    j++;
            }
        }
        return i * n + j;
    }
};